#include<iostream>
using namespace std;
#include<vector>
#include<unordered_set>
class Solution {
public:
    int mincostTickets(vector<int>& days, vector<int>& costs) {
        unordered_set<int> search;
        for (auto& e : days)
            search.insert(e);
        int arr[366] = { 0 }, cheap = min(costs[0], min(costs[1], costs[2]));
        for (int i = 1; i <= days.back(); ++i) {
            if (search.count(i) == 0)
                arr[i] = arr[i - 1];
            else {
                arr[i] = arr[i - 1] + cheap;
                if (i - 7 >= 0)
                    arr[i] = min(arr[i], arr[i - 7] + costs[1]);
                else
                    arr[i] = min(arr[i], costs[1]);
                if (i - 30 >= 0)
                    arr[i] = min(arr[i], arr[i - 30] + costs[2]);
                else
                    arr[i] = min(arr[i], costs[2]);
            }
        }
        return arr[days.back()];
    }
};
int main() {
    vector<int> days{ 6,8,9,18,20,21,23,25 }, costs{ 2,10,41 };
    Solution().mincostTickets(days, costs);
}